package mx.com.crowdgine.game;

import javax.media.opengl.GL4bc;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.glu.GLU;

import mx.com.crowdgine.app.JoglApplication;
import mx.com.crowdgine.assetloader.RawTexture;
import mx.com.crowdgine.camera.JoglCamera;
import mx.com.crowdgine.entity.Entity;
import mx.com.crowdgine.entity.geometry.Plane;
import mx.com.crowdgine.util.math.Vector3f;

import com.jme3.input.MouseInput;

public class TextureLoader extends JoglApplication {
	
	public Entity plane;
	public RawTexture rawTexture;

	public TextureLoader(String frameName, int width, int height){
		super(frameName, width, height);
	}
	
	public static void main(String [] args){
		TextureLoader game= new TextureLoader("Texture happiness loader",640,480);
		game.start();
	}
	
	@Override
	public void initialize(){
		super.initialize();
		addAndSetCamera(new JoglCamera());
		plane = new Plane(4.0f, new Vector3f(0.2f, 0.4f, 0.8f));
		//plane.translate(new Vector3f(5,0,0));
		addEntity(plane);
	}
	
	@Override
	public void init(GLAutoDrawable drawable){
		super.init(drawable);
		System.out.println("Init Drawable");
		GL4bc gl = getBestGlImplementation(drawable);
		rawTexture=new RawTexture(256,256,4,"Assets/textures/monitor.raw");
		GLU glu = new GLU();
		((Plane)plane).initRawTexture(rawTexture,gl,glu);
	}
	
	@Override
	public void initInput(){
		super.initInput();
		
		addMouseButtonMapping("Jump", MouseInput.BUTTON_LEFT,MouseInput.BUTTON_RIGHT);
	}
	
	@Override
	public void update(GLAutoDrawable drawable){
		super.update(drawable);
		inputManager.update();
	}
	
	@Override
	protected void updateActionListener(String name, boolean pressed){
		super.updateActionListener(name, pressed);
		if(name=="Jump" && pressed){
			System.out.println("ROFL");
		}
	}
	
	@Override
	protected void updateAnalogListener(String name, float value){
		super.updateAnalogListener(name, value);
		if(name=="MouseLeft"){
			System.out.println("Left! value: "+value);
		}
		if(name=="MouseRight"){
			System.out.println("Right! value: "+value);
		}
		if(name=="MouseUp"){
			System.out.println("Up! value: "+value);
		}
		if(name=="MouseDown"){
			System.out.println("Down! value: "+value);
		}
	}
	
}
